<template>
  <footer class="footer" v-if="list.length > 0">
    <!-- This should be `0 items left` by default -->
    <span class="todo-count"
      ><strong>{{ letCount }}</strong> item left</span
    >
    <!-- Remove this if you don't implement routing -->
    <ul class="filters">
      <li>
        <a
          :class="{ selected: type === 'all' }"
          @click.prevent="filter('all')"
          href="#/"
          >All</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'active' }"
          @click.prevent="filter('active')"
          href="#/active"
          >Active</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'completed' }"
          @click.prevent="filter('completed')"
          href="#/completed"
          >Completed</a
        >
      </li>
    </ul>
    <!-- Hidden if no completed items are left ↓ -->
    <button class="clear-completed" v-show="isShow" @click="clear">
      Clear completed
    </button>
  </footer>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      required: true,
    },
    type: {
      type: String,
      default: "all",
    },
  },
  computed: {
    letCount() {
      // 精简
      return this.list.filter((item) => !item.isDone).length;
      // 正常
      // let num = this.list.filter((item) => !item.isDone);
      // return num.length;
    },
    isShow() {
      return this.list.some((item) => item.isDone);
    },
  },
  methods: {
    clear() {
      this.$emit("clear");
    },
    filter(type) {
      this.$emit("filter", type);
    },
  },
};
</script>

<style>
</style>